package cn.net.Serializable;

import java.io.Serializable;

/**本类用来封装学生类*/
/*
   如果本类想要完成序列化,必须实现可序列化接口,否则会报错:java.io.NotSerializableException
 * Serializable接口是一个空接口,里面一个方法都没有,作用是用来当做标志,标志这个类可以序列化/反序列化
 */
public class Student implements Serializable {//实现接口
    /**需要给每个进行序列化的文件分配唯一的UID值*/
    private static final long serialVersionUID = -3193364654654535741L;
    //private封装
    private String name;
    private int age;
    private char sex;
    private  int id;

    public Student() {
    }

    public Student(String name, int age, char sex, int id) {
        this.name = name;
        this.age = age;
        this.sex = sex;
        this.id = id;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
    //toString()
   //打印结果:cn.tedu.serializable.Student@4c873330-->地址值
    //想看对象序列化后的属性值,需要重写toString()
    @Override
    public String toString() {
        return "TestStudent{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex=" + sex +
                ", id=" + id +
                '}';
    }
}
